home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / utility / speed_3.s < prev    next >
Text File  |  1985-11-19  |  7KB  |  165 lines

  1.  ; Program Name: SPEED_3.S
  2.  ; Version 1.004
  3.  
  4.  ; NOTE: This program is similar to SPEED_2.  The differences are that a
  5.  ;       different algorithm is used to process the command line, and no user
  6.  ;       stack is declared in SPEED_3.
  7.  
  8.  ; Assembly Instructions:
  9.  
  10.  ;     Assemble in "PC-relative" mode and save with a TTP extension. 
  11.  
  12.  ; Function:
  13.  
  14.  ;     Spawn a process and calculate the spawned program's load and execution
  15.  ; times.  Pause for a keypress before terminating.
  16.  
  17. release_excess_memory:
  18.  lea        program_end, a0     ; Put "end of program" address in A0.
  19.  movea.l    4(a7), a1           ; Put "basepage" address in A1.
  20.  lea        $80(a1), a3         ; Put "command line" address in A3.
  21.  trap       #6                  ; Calculate program size and release memory.
  22.  
  23.  ; NOTE: A local stack is not declared in PRG_5AP.TOS.  Because of the long
  24.  ;       string that is printed by that program, this program will bomb when
  25.  ;       it spawns PRG_5AP.TOS, if a local stack is not declared here.
  26.   
  27.  lea        stack, a7           ; Point A7 to this program's stack.
  28.  
  29.  ;                    COMMAND LINE PROCESSING NOTE
  30.  
  31.  ;     At this point register A3 contains the address of the command line.
  32.  ; In the algorithm below, the address of the first ASCII character in the
  33.  ; command line input is stored at the pointer "program_name".  Then a NULL
  34.  ; character is written over the carriage return code at the end of the
  35.  ; command line input.  Thus the command line input itself becomes the
  36.  ; string, the address of which must be pushed on the stack during the p_exec
  37.  ; invocation.
  38.  
  39.  ;     Even though register A3 contains the address of the program name string,
  40.  ; and the contents of A3 can be pushed during the p_exec invocation, the
  41.  ; address of the string must be stored in a declared location because 
  42.  ; register A3 might be used by the spawned program.  And the address of the
  43.  ; string is still needed to print the spawned program's name in SPEED_3's
  44.  ; output heading.
  45.  
  46. process_command_line:
  47.  lea        command_line, a4    ; Fetch location to contain command line.
  48.  movem.l    (a3), d0-d3         ; Move 16 bytes of command line to 4 registers.
  49.  movem.l    d0-d3, (a4)         ; Move them to address "command_line".
  50.  move.b     (a3)+, d0           ; Fetch parameter line input character count.
  51.  ext.w      d0                  ; Extend to word for next instruction.
  52.  move.b     #0, 1(a4,d0.w)      ; Store a null at end of string.
  53.  lea        program_name, a0    ; Fetch address of pointer to program name.
  54.  move.l     a3, (a0)            ; Store address of program name in pointer.
  55.  move.b     #0, 0(a3,d0.w)      ; Replace $0D at end of program name with NULL.
  56.          
  57. insert_filename_suffix:
  58.  move.b     #$44, -2(a4,d0.w)   ; Insert letter 'D'.
  59.  move.b     #$41, -1(a4,d0.w)   ; Insert letter 'A'.
  60.  move.b     #$54,  0(a4,d0.w)   ; Insert letter 'T'.
  61.                       
  62. create_file:
  63.  move.w     #0, -(sp)           ; File attribute = read/write.
  64.  pea        filename            ; Will be name of spawned process + .DAT.
  65.  move.w     #$3C, -(sp)         ; Function = f_create = GEMDOS $3C.
  66.  trap       #1                  ; File handle is returned in D0.
  67.  addq.l     #8, sp
  68.  lea        file_handle, a0
  69.  move.w     d0, (a0)
  70.  
  71. redirect_output:                ; Exchange file handle with screen's handle.
  72.  move.w     file_handle, -(sp)  ; This is the disk file's handle.
  73.  move.w     #1, -(sp)           ; This is the video screen's handle.
  74.  move.w     #$46, -(sp)         ; Function = f_force = GEMDOS $46.
  75.  trap       #1
  76.  addq.l     #6, sp
  77.  
  78. prepare_stack_for_load_and_execute_program:      
  79.  pea        environ_string
  80.  pea        command_string
  81.  pea        (a3)                ; Push address of program name string.
  82.  move.w     #0, -(sp)
  83.  move.w     #$4B, -(sp)         ; Function = GEMDOS $4B = p_exec.
  84.  
  85. get_start_time:
  86.  lea        start_time, a3      ; Fetch address of variable "start_time".
  87.  trap       #3                  ; Returns value of system clock in D0.
  88.  move.w     d0, (a3)            ; Save start time.
  89. load_and_execute_program:
  90.  trap       #1                 
  91.  move.w     d0, d3              ; Copy after-load value to D3 for calculation.
  92.  
  93. get_end_time:
  94.  trap       #3                  ; Returns value of system clock in D0.
  95.  move.w     d0, d5              ; Copy to D5 for calculation.
  96.  sub.w      d3, d5              ; Subtract after-load time from end time.
  97.  ext.l      d5                  ; Extend to 32 bits.
  98.  
  99. reposition_stack_pointer:
  100.  lea        $10(sp), sp        
  101.  
  102. get_drive:
  103.  move.w     #$19, -(sp)         ; Function = dgetdrv = GEMDOS $19.
  104.  trap       #1
  105.  addq.l     #2, sp
  106.  add.b      #'A', d0
  107.  lea        drive, a0
  108.  move.b     d0, (a0)
  109.  
  110. print_heading:
  111.  lea        heading, a0
  112.  bsr        print_string
  113.  lea        program_name, a0     ; Fetch address of program name string.
  114.  movea.l    (a0), a0
  115.  bsr        print_string         ; Print spawned program's name.
  116. print_drive_for_spawned_program:
  117.  lea        drive_msg, a0        ; Print drive from which spawned program was
  118.  bsr        print_string         ; loaded.
  119.  
  120. compute_load_time:
  121.  lea        load_time_msg, a0
  122.  bsr        print_string
  123.  lea        start_time, a3
  124.  sub.w      (a3), d3            ; Subtract start time from after-load time.
  125.  ext.l      d3                  ; Extent to 32 bits.
  126.  trap       #9                  ; See description in TRAPS.S.
  127.  
  128. close_file:
  129.  move.w     file_handle, -(sp)
  130.  move.w     #$3E, -(sp)         ; Function = fclose = GEMDOS $3E.
  131.  trap       #1
  132.  addq.l     #4, sp
  133.  
  134. terminate:
  135.  move.w     #0, -(sp)
  136.  trap       #1
  137.  
  138. print_string:                   ; Expects address of string to be in A0.
  139.  move.l     a0, -(sp)           ; Push address of string onto stack.
  140.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  141.  trap       #1                  ; GEMDOS call
  142.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  143.  rts
  144.  
  145.  data
  146. heading:          dc.b $D,$A,"SPEED_3.TTP Execution Results",$D,$A
  147.                   dc.b       "for ",0
  148. drive_msg:        dc.b ", loaded from drive: "
  149. drive:            dc.b "A",$D,$A,0
  150. load_time_msg:    dc.b $D,$A,"  Load time:    ",0
  151. environ_string:   dc.b "TERM",0
  152. command_string:   dc.b 0
  153.  align
  154.  bss
  155. start_time:       ds.w    1
  156. program_name:     ds.l    1     ; Pointer to string in basepage command line.
  157. file_handle:      ds.w    1
  158. command_line:     ds.b    1     ; Unused character count will go here.
  159. filename:         ds.b   15     ; File name for redirected output.
  160.                   ds.l   96     ; Program stack.
  161. stack:            ds.l    0     ; Address of program stack.
  162. program_end:      ds.l    0
  163.  end
  164.  
  165.